package com.example.administrator.sizhang_jineng;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/11/5.
 */

public class Erladpater extends BaseExpandableListAdapter{
    private  ArrayList<String> mGroup;
    private  ArrayList<ArrayList<String>> mItem;

    public Erladpater(ArrayList<String> group, ArrayList<ArrayList<String>> twoData) {
             this.mGroup=group;
             this.mItem=twoData;
    }

    @Override
    public int getGroupCount() {
        return mGroup.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return mItem.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return mGroup.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return mItem.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.group, null, false);
        TextView  tv=inflate.findViewById(R.id.tv);
        tv.setText(mGroup.get(groupPosition));
        return inflate;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, null, false);
        TextView  tv=inflate.findViewById(R.id.tv);
        tv.setText(mItem.get(groupPosition).get(childPosition));
        return inflate;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
